/**
 * ItemDAO.java
 * @author GorillaFunch
 * @created 2012.10.12
 */
package kr.ac.kongju.gedl.index.dao;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javax.sql.DataSource;

import kr.ac.kongju.gedl.item.vo.ItemFileVO;
import kr.ac.kongju.gedl.item.vo.ItemVO;
import kr.ac.kongju.gedl.item.vo.ItemLevelVO;
import kr.ac.kongju.gedl.item.vo.ItemLinkVO;
import kr.ac.kongju.gedl.item.vo.ItemVO;
import kr.ac.kongju.gedl.item.vo.ItemXmlVO;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import egovframework.rte.psl.dataaccess.EgovAbstractDAO;

@Repository("indexDAO")
public class IndexDAO extends EgovAbstractDAO{
	private final Logger logger = LoggerFactory.getLogger(getClass());
	
	
	/**
	 * retrieveListCountItemInfo
	 * ItemInfo 검색결과 수
	 * @param itemInfo
	 * @return
	 * @throws Exception
	 */
	public int retrieveItemCount(ItemVO searchCondition){
		int count = 0;
		try {
			count = ((Integer)getSqlMapClientTemplate().queryForObject("Index.retrieveItemCount", searchCondition)).intValue();
			logger.debug("Index.retrieveItemCount count:{}", count);
		} catch (Exception e) {
			logger.error("cause:{}", e.toString());   
		} 	
		return count;
	}
	
	/**
	 * retrieveListItemInfo
	 * ItemInfo 검색
	 * @param itemInfo
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public List<ItemVO> retrieveItemList(ItemVO searchCondition)throws Exception {
		List<ItemVO> list = list("Index.retrieveItemList", searchCondition);
		logger.debug("Index.retrieveListItemInfo size:{}", list.size());
		return list;
	}
	
	
	/**
	 * retrieveListItemInfo
	 * ItemInfo 검색
	 * @param itemInfo
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public ItemVO retrieveItemInfo(ItemVO searchCondition)throws Exception {
		ItemVO vo = (ItemVO)selectByPk("Index.retrieveItemInfo", searchCondition);
		return vo;
	}
	
	/**
	 * registerItemInfo
	 * 아이템정보 등록
	 * @param itemInfo
	 * @return
	 * @throws Exception 실패시
	 */
	public ItemVO registerItemInfo(ItemVO itemInfo){
		try{
			String itemId = (String) getSqlMapClientTemplate().insert("Index.registerItemInfo", itemInfo);
			itemInfo.setItemId(itemId);
		}catch(Exception e){
			itemInfo = null;
			logger.error("cause:{}", e.toString());
		}
		return itemInfo;
	}
	
	
}